home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
emerald
/
emrldsys.lha
/
Language
/
Compiler
/
sequence.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-16
|
2KB
|
86 lines
/*
* @(#)sequence.c 1.3 6/29/87
*/
#include "nodes.h"
#include "sequence.h"
#include "assert.h"
NodePtr Sequence_Add(s, n)
NodePtr *s, n;
{
register NodePtr p = *s;
register int length;
if (p == NULL) {
(*s) = F_NewNode(T_SEQUENCE, 4);
p = (*s);
p->nChildren = 0;
} else if (p->nChildren >= p->maxChildren) {
length = p->maxChildren;
(*s) = F_NewNode(p->tag, 2 * length);
bcopy((char *)p, (char *)(*s), NodeSize(p));
(*s)->maxChildren = 2 * length;
free((char *)p);
p = (*s);
}
if (p->nChildren == 0 && (int) n > 0x200) p->lineNumber = n->lineNumber;
p->b.children[p->nChildren] = n;
p->nChildren++;
}
NodePtr Sequence_AddFirst(s, n)
NodePtr *s, n;
{
register NodePtr p = *s;
register int length;
if (p == NULL) {
(*s) = F_NewNode(T_SEQUENCE, 4);
p = (*s);
p->nChildren = 0;
} else if (p->nChildren >= p->maxChildren) {
length = p->maxChildren;
(*s) = F_NewNode(p->tag, 2 * length);
bcopy((char *)p, (char *)(*s), NodeSize(p));
(*s)->maxChildren = 2 * length;
free((char *)p);
p = (*s);
}
assert(p->firstChild == 0);
for (length = p->nChildren - 1; length >= 0; length--)
p->b.children[length+1] = p->b.children[length];
p->nChildren++;
p->b.children[0] = n;
}
void Sequence_Free(s)
register NodePtr s;
{
register int i;
for (i = s->firstChild; i < s->nChildren; i++) {
FreeNode(s->b.children[i]);
}
}
void Sequence_RemoveSeparators(n)
NodePtr n;
{
register int i, j = 1;
assert(n->tag == T_SEQUENCE);
for (i = 2; i < n->nChildren; i+=2) {
n->b.children[j++] = n->b.children[i];
}
n->nChildren = j;
}
NodePtr Sequence_Construct(n, first)
int n;
NodePtr first;
{
register int i;
register NodePtr *a = &first, p;
p = F_NewNode(T_SEQUENCE, n);
p->nChildren = n;
for (i = 0; i < n; i++)
p->b.children[i] = a[i];
return(p);
}